// 初始化
$(function (){

	// 评论加载
	LoadMessageList();

	CheckReplyMaxLen();

});


var messageWaitTime = 0;
var messageCutWaitFunc = null;
// 评论回复
function CheckMessageForm(){
	if ($id('messContent').value==""){
		alert('留言内容不能为空');$id('messContent').focus();return false;
	}
	if ($id('messContent').value.length<5){
		alert('留言内容不能少于5字符');$id('messContent').focus();return false;
	}
	strMaxLen = parseInt($id('messContentMaxLen').value);
	if ($id('messContent').value.length>strMaxLen && strMaxLen>0){
		alert('留言内容超过最大'+ strMaxLen +'字符限制');$id('messContent').value=$id('messContent').value.substring(0,strMaxLen);CalcReplyLen();return false;
	}
	if ($id('messUser').value==""){
		alert('昵称不能为空');$id('messUser').focus();return false;
	}
	try {
		if ($id('verCode').value==""){
			alert('验证码不能为空');$id('verCode').focus();return false;
		}
	}catch (e) {}

	if (messageWaitTime>0){
		alert("已提交，请稍等一会儿...("+ messageWaitTime +")");return false;
	}
		messageWaitTime = 3;
		messageCutWaitFunc = window.setInterval("CutMessageWaitTime()",1000);

	AjaxPostDeal("messageForm");
	return false;
}

function CutMessageWaitTime(){
	if (messageWaitTime<=0){
		window.clearInterval(messageCutWaitFunc);
		return false;
	}else{
		messageWaitTime --;
	}
}


// 读取评论区信息
function LoadMessageList(){
	$id("messageList").innerHTML = "<center style='padding:10px;'><img src='"+ dbPathPart +"inc_img/onload.gif' style='margin-right:5px;' />数据加载中...</center>"+ $id("messageList").innerHTML;
	AjaxGetDealToId(dbPathPart +"deal.asp?mudi=messageSend&dataType=message","messageList");
}


// 检测回复内容字符
function CheckReplyMaxLen(){
	strMaxLen = parseInt($id('messContentMaxLen').value);
	if (strMaxLen>0){
		$id('conMaxLenBox').innerHTML = "(<span id='conCurrLen'>0</span>/"+ strMaxLen +")&nbsp;";
		$('#messContent').keyup(function (){
			CalcReplyLen();
		});
	}
}

// 计算回复内容字符数
function CalcReplyLen(){
	try {
		$id('conCurrLen').innerHTML = $id('messContent').value.length;
	}catch (e) {}
}